package com.java.tutorials.jdk7.locale;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Locale.Builder;
/**
 * Created by xuzhike on 2016/1/27.
 * http://www.java2s.com/Code/Java/JDK-7/CreateLocalewithLocaleBuilder.htm
 * Create Locale with Locale Builder
 */
public class CreateLocalewithLocaleBuilder {
    public static void main(String[] args) {
        long SAMPLE_NUMBER = 123456789L;
        Date NOW = new Date();
        String[][] langRegions = { { "fr", "FR" }, { "ja", "JP" }, { "en", "US" } };
        Builder builder = new Builder();
        Locale l = null;
        for (String[] lr : langRegions) {
            builder.clear();
            builder.setLanguage(lr[0]).setRegion(lr[1]);
            l = builder.build();
            displayLocalizedData(l, SAMPLE_NUMBER, NOW);
        }
    }

    static void displayLocalizedData(Locale l, long number, Date date) {
        NumberFormat nf = NumberFormat.getInstance(l);
        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG,
                DateFormat.LONG, l);
        System.out.printf("Locale: %s\nNumber: %s\nDate: %s\n\n",
                l.getDisplayName(), nf.format(number), df.format(date));
    }
}
